<template>
  <div class="address-bg">
    <div class="address"></div>
    <van-address-edit
      :area-list="areaList"
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="saveClick"
      @change-detail="onChangeDetail"
    />
  </div>
</template>

<script>
import { mapGetters, mapState } from "vuex";
import { areaList } from "@vant/area-data";

export default {
  name: "AddressAdd",
  data() {
    return {
      areaList,
      searchResult: [],
    };
  },
  methods: {
    //
    saveClick(content) {
      //
      let area = content.province + "-" + content.city + "-" + content.county;
      let form = {
        name: content.name,
        tel: content.tel,
        area: area,
        detail: content.addressDetail,
      };
      //请求接口添加到地址中
      this.$http.post("http://localhost:8080/address/add", form,{
          headers: {
            "Content-Type": "application/x-www-form-urlencoded",
          },
        });
      this.$router.push("/user/address");
    },
    //
    onChangeDetail(val) {
      if(val){
        this.searchResult=[
          {
            name:'黄龙万科中心',
            address:'杭州市西湖区'
          }
        ]
      }else{
        this.searchResult=[]
      }
    },
  },
};
</script>

<style scoped>
.address-bg {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgb(247, 248, 250);
}
.address {
  margin-top: 150px;
}
</style>